package options;

import gui.OptionsTest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 * Optionsfenster der Kontakte
 * 
 * @author Michi
 * 
 */
public class KontakteOptionPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4366132715249688489L;
	private String[] windowColorsSeperated;
	private JRadioButton rdbtnNachVorname;
	private JRadioButton rdbtnNachNachname;
	private JRadioButton rdbtnVornameNachname;
	private JRadioButton rdbtnNachnameVorname;

	// Sprache
	int speak = 0;
	String[] sort = { "Sortierung", "Sorting", "Diribitio" };
	String[] vorname = { "nach Vorname", "by first name", "Per primam nominis" };
	String[] nachname = { "nach Nachname", "by name", "nomine" };
	String[] darstellung = { "Darstellung", "Representation", "Imago" };
	String[] vorNach = { "Vorname, Nachname", "first name, last name",
			"Primum nomen, ultimum nomen" };
	String[] nachVor = { "Nachname, Vorname", "last name, first name",
			"Ultimum nomen, primum nomen" };

	/**
	 * Create the panel.
	 */
	public KontakteOptionPanel(final OptionsTest optionsTestInstance) {
		speak = Integer.parseInt(optionsTestInstance.getOr().getLanguage());

		String windowColors = optionsTestInstance.getOr().getColorSetting();
		windowColorsSeperated = windowColors.split(",");
		setBackground(new Color(Integer.parseInt(windowColorsSeperated[0]),
				Integer.parseInt(windowColorsSeperated[1]),
				Integer.parseInt(windowColorsSeperated[2])));
		setMinimumSize(new Dimension(600, 700));
		setMaximumSize(new Dimension(600, 700));
		setPreferredSize(new Dimension(600, 700));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		setLayout(gridBagLayout);

		JLabel lblOption = new JLabel(sort[speak]);
		lblOption.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_lblOption = new GridBagConstraints();
		gbc_lblOption.anchor = GridBagConstraints.WEST;
		gbc_lblOption.insets = new Insets(0, 0, 5, 5);
		gbc_lblOption.gridx = 0;
		gbc_lblOption.gridy = 1;
		add(lblOption, gbc_lblOption);

		JLabel dummyLabel0 = new JLabel("   ");
		dummyLabel0.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel0 = new GridBagConstraints();
		gbc_dummyLabel0.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel0.gridx = 0;
		gbc_dummyLabel0.gridy = 2;
		add(dummyLabel0, gbc_dummyLabel0);

		rdbtnNachVorname = new JRadioButton(vorname[speak]);
		rdbtnNachVorname.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				rdbtnNachVorname.setSelected(true);
				rdbtnNachNachname.setSelected(false);
				optionsTestInstance.setConOpt1("0");
			}
		});
		GridBagConstraints gbc_rdbtnNachVorname = new GridBagConstraints();
		gbc_rdbtnNachVorname.anchor = GridBagConstraints.WEST;
		gbc_rdbtnNachVorname.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnNachVorname.gridx = 2;
		gbc_rdbtnNachVorname.gridy = 3;
		add(rdbtnNachVorname, gbc_rdbtnNachVorname);

		rdbtnNachNachname = new JRadioButton(nachname[speak]);
		rdbtnNachNachname.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnNachVorname.setSelected(false);
				rdbtnNachNachname.setSelected(true);
				optionsTestInstance.setConOpt1("1");
			}
		});
		GridBagConstraints gbc_rdbtnNachNachname = new GridBagConstraints();
		gbc_rdbtnNachNachname.anchor = GridBagConstraints.WEST;
		gbc_rdbtnNachNachname.insets = new Insets(0, 0, 5, 0);
		gbc_rdbtnNachNachname.gridx = 4;
		gbc_rdbtnNachNachname.gridy = 3;
		add(rdbtnNachNachname, gbc_rdbtnNachNachname);

		JLabel dummyLabel2 = new JLabel("   ");
		dummyLabel2.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel2 = new GridBagConstraints();
		gbc_dummyLabel2.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel2.gridx = 0;
		gbc_dummyLabel2.gridy = 4;
		add(dummyLabel2, gbc_dummyLabel2);

		JLabel lblOption_1 = new JLabel(darstellung[speak]);
		lblOption_1.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_lblOption_1 = new GridBagConstraints();
		gbc_lblOption_1.anchor = GridBagConstraints.WEST;
		gbc_lblOption_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblOption_1.gridx = 0;
		gbc_lblOption_1.gridy = 5;
		add(lblOption_1, gbc_lblOption_1);

		JLabel dummyLabel1 = new JLabel("   ");
		dummyLabel1.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel1 = new GridBagConstraints();
		gbc_dummyLabel1.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel1.gridx = 0;
		gbc_dummyLabel1.gridy = 6;
		add(dummyLabel1, gbc_dummyLabel1);

		rdbtnVornameNachname = new JRadioButton(vorNach[speak]);
		rdbtnVornameNachname.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnVornameNachname.setSelected(true);
				rdbtnNachnameVorname.setSelected(false);

				optionsTestInstance.setConOpt2("0");
			}
		});
		GridBagConstraints gbc_rdbtnVornameNachname = new GridBagConstraints();
		gbc_rdbtnVornameNachname.anchor = GridBagConstraints.WEST;
		gbc_rdbtnVornameNachname.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnVornameNachname.gridx = 2;
		gbc_rdbtnVornameNachname.gridy = 7;
		add(rdbtnVornameNachname, gbc_rdbtnVornameNachname);

		rdbtnNachnameVorname = new JRadioButton(nachVor[speak]);
		rdbtnNachnameVorname.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnVornameNachname.setSelected(false);
				rdbtnNachnameVorname.setSelected(true);
				optionsTestInstance.setConOpt2("1");
			}
		});
		GridBagConstraints gbc_rdbtnNachnameVorname = new GridBagConstraints();
		gbc_rdbtnNachnameVorname.anchor = GridBagConstraints.WEST;
		gbc_rdbtnNachnameVorname.insets = new Insets(0, 0, 5, 0);
		gbc_rdbtnNachnameVorname.gridx = 4;
		gbc_rdbtnNachnameVorname.gridy = 7;
		add(rdbtnNachnameVorname, gbc_rdbtnNachnameVorname);

		JLabel dummyLabel3 = new JLabel("   ");
		dummyLabel3.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel3 = new GridBagConstraints();
		gbc_dummyLabel3.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel3.gridx = 0;
		gbc_dummyLabel3.gridy = 8;
		add(dummyLabel3, gbc_dummyLabel3);

		if (optionsTestInstance.getConOpt1().equals("0")) {
			rdbtnNachVorname.setSelected(true);
		} else {
			rdbtnNachNachname.setSelected(true);
		}

		if (optionsTestInstance.getConOpt2().equals("0")) {
			rdbtnVornameNachname.setSelected(true);
		} else {
			rdbtnNachnameVorname.setSelected(true);
		}

	}

}
